from MCP23017 import send_command, send_data

ROMUnOrderMap = {
    # 20H - 7FH
    0x00A5: 0x5C, # '¥' 原先是'\'，罗马字下的'\'键就是'¥'
    0x2192: 0x7E, # '→' 原先是'~'
    0x2190: 0x7F, # '←'
    # 20H - 7FH
    0x3002: 0xA1, # '。' 日语的句号
    0x300C: 0xA2, # '「' 日语的引号
    0x300D: 0xA3, # '」' 日语的引号
    0x3001: 0xA4, # '、' 日语的逗号
    0x30DB: 0xA5, # '・' 日语的中点号，日语下的'?'键就是'・'
    0x30F2: 0xA6, # 'ヲ' wo
    0x30A1: 0xA7, # 'ァ' 日语合成音
    0x30A3: 0xA8, # 'ィ' 
    0x30A5: 0xA9, # 'ゥ' 
    0x30A7: 0xAA, # 'ェ'
    0x30A9: 0xAB, # 'ォ' 
    0x30E3: 0xAC, # 'ャ' 日语坳音的复元音
    0x30E5: 0xAD, # 'ュ'
    0x30E7: 0xAE, # 'ョ'
    0x30C3: 0xAF, # 'ッ' 日语促音
    0x30FC: 0xB0, # 'ー' 日语长音
    0x30A2: 0xB1, # 'ア'
    0x30A4: 0xB2, # 'イ'
    0x30A6: 0xB3, # 'ウ'
    0x30A8: 0xB4, # 'エ'
    0x30AA: 0xB5, # 'オ'
    0x30AB: 0xB6, # 'カ'
    0x30AD: 0xB7, # 'キ'
    0x30AF: 0xB8, # 'ク'
    0x30B1: 0xB9, # 'ケ'
    0x30B3: 0xBA, # 'コ'
    0x30AC: [0xB6, 0xDE], # 'ガ'
    0x30AE: [0xB7, 0xDE], # 'ギ'
    0x30B0: [0xB8, 0xDE], # 'グ'
    0x30B2: [0xB9, 0xDE], # 'ゲ'
    0x30B4: [0xBA, 0xDE], # 'ゴ'
    0x30B5: 0xBB, # 'サ'
    0x30B7: 0xBC, # 'シ'
    0x30B9: 0xBD, # 'ス'
    0x30BB: 0xBE, # 'セ'
    0x30BD: 0xBF, # 'ソ'
    0x30B6: [0xBB, 0xDE], # 'ザ'
    0x30B8: [0xBC, 0xDE], # 'ジ'
    0x30BA: [0xBD, 0xDE], # 'ズ'
    0x30BC: [0xBE, 0xDE], # 'ゼ'
    0x30BE: [0xBF, 0xDE], # 'ゾ'
    0x30BF: 0xC0, # 'タ'
    0x30C1: 0xC1, # 'チ'
    0x30C4: 0xC2, # 'ツ'
    0x30C6: 0xC3, # 'テ'
    0x30C8: 0xC4, # 'ト'
    0x30C0: [0xC0, 0xDE], # 'ダ'
    0x30C2: [0xC1, 0xDE], # 'ヂ'
    0x30C5: [0xC2, 0xDE], # 'ヅ'
    0x30C7: [0xC3, 0xDE], # 'デ'
    0x30C9: [0xC4, 0xDE], # 'ド'
    0x30CA: 0xC5, # 'ナ'
    0x30CB: 0xC6, # 'ニ'
    0x30CC: 0xC7, # 'ヌ'
    0x30CD: 0xC8, # 'ネ'
    0x30CE: 0xC9, # 'ノ'
    0x30cf: 0xCA, # 'ハ'
    0x30d2: 0xCB, # 'ヒ'
    0x30d5: 0xCC, # 'フ'
    0x30d8: 0xCD, # 'ヘ'
    0x30db: 0xCE, # 'ホ'
    0x30d0: [0xCA, 0xDE], # 'バ'
    0x30d3: [0xCB, 0xDE], # 'ビ'
    0x30d6: [0xCC, 0xDE], # 'ブ'
    0x30d9: [0xCD, 0xDE], # 'ベ'
    0x30dc: [0xCE, 0xDE], # 'ボ'
    0x30d1: [0xCA, 0xDF], # 'パ'
    0x30d4: [0xCB, 0xDF], # 'ピ'
    0x30d7: [0xCC, 0xDF], # 'プ'
    0x30da: [0xCD, 0xDF], # 'ペ'
    0x30dd: [0xCE, 0xDF], # 'ポ'
    0x30de: 0xCF, # 'マ'
    0x30df: 0xD0, # 'ミ'
    0x30e0: 0xD1, # 'ム'
    0x30e1: 0xD2, # 'メ'
    0x30e2: 0xD3, # 'モ'
    0x30e4: 0xD4, # 'ヤ'
    0x30e6: 0xD5, # 'ユ'
    0x30e8: 0xD6, # 'ヨ'
    0x30e9: 0xD7, # 'ラ'
    0x30ea: 0xD8, # 'リ'
    0x30eb: 0xD9, # 'ル'
    0x30ec: 0xDA, # 'レ'
    0x30ED: 0xDB, # 'ロ'
    0x30EF: 0xDC, # 'ワ'
    0x30f3: 0xDD, # 'ン'
    0x03B1: 0xE0, # 'α'
    0x00E4: 0xE1, # 'ä'
    0x03B2: 0xE2, # 'β'
    0x03B5: 0xE3, # 'ε'
    0x03BC: 0xE4, # 'μ'
    0x03C3: 0xE5, # 'σ'
    0x03C1: 0xE6, # 'ρ'
    # 0xE7为g，可能为日语g
    0x221A: 0xE8, # '√'
    # 0xE9可能为-1次方
    # 0xEA为j，可能为日语j
    # 0xEB可能为上角标
    # 0xEC - 0xED没识别出来
    0x00F1: 0xEE, # 'ñ'
    0x00F6: 0xEF, # 'ö'
    # 0xF0为p，可能为日语p
    # 0xF1为q，可能为日语q
    0x03B8: 0xF2, # 'θ'
    0x221E: 0xF3, # '∞'
    0x03A9: 0xF4, # 'Ω'
    0x00FC: 0xF5, # 'ü'
    0x03A3: 0xF6, # 'Σ'
    0x03C0: 0xF7, # 'π'
    # 0xF8可能为均值
    # 0xF8为y，可能为日语y
    0x5343: 0xFA, # '千'
    0x4E07: 0xFB, # '万'
    0x5186: 0xFC, # '円'
    0x00F7: 0xFD, # '÷'
}

DefaultRAMUnOrderMap = {
    "switch": False,
    "日": 0,
    "月": 1,
    "年": 2,
    "二": 3,
    "上": 4,
    "下": 5,
    "左": 6,
    "右": 7
}

DefaultRAMContent = {
    "日": [0x1F, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x1F, 0x00],
    "月": [0x1F, 0x11, 0x1F, 0x11, 0x1F, 0x11, 0x11, 0x00],
    "年": [0x08, 0x0F, 0x12, 0x0F, 0x0A, 0x1F, 0x02, 0x00],
    "二": [0x00, 0x00, 0x0E, 0x00, 0x1F, 0x00, 0x00, 0x00],
    "上": [0x08, 0x08, 0x08, 0x0E, 0x08, 0x08, 0x1F, 0x00],
    "下": [0x1F, 0x08, 0x08, 0x0C, 0x0A, 0x08, 0x08, 0x00],
    "左": [0x04, 0x1F, 0x08, 0x17, 0x02, 0x02, 0x0F, 0x00],
    "右": [0x04, 0x1F, 0x08, 0x17, 0x09, 0x09, 0x0F, 0x00]
}


def injectRAMContent(RAMContent):
    cnt = 0
    for key in RAMContent:
        DefaultRAMUnOrderMap[key] = cnt
        send_command(0x40+cnt*8)
        for temp in RAMContent[key]:
            send_data(temp)
        cnt += 1
    DefaultRAMUnOrderMap['switch'] = True